package com.gz.moreaseManager.modules.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.gz.moreaseManager.core.base.Constants;
import com.gz.moreaseManager.core.enums.YesOrNoEnum;
import com.gz.moreaseManager.modules.entity.Banner;
import com.gz.moreaseManager.modules.mapper.BannerMapper;
import com.gz.moreaseManager.modules.service.IBannerService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gz.moreaseManager.utils.UtilTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 轮播图信息 服务实现类
 * </p>
 *
 * @author wike
 * @since 2019-02-21
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements IBannerService {

    @Resource
    private BannerMapper bannerMapper;

    @Override
    public Map<String, Banner> findAllMapBanner() {
        Map<String, Banner> bannerMap =new HashMap<>();
        Wrapper wrapper = new EntityWrapper<Banner>();
        wrapper.eq("banner_type",4);//获取官网导航栏图片
        wrapper.eq("status",1);//必须是显示的数据
        List<Banner> bannerList = bannerMapper.selectList(wrapper);
        if(UtilTool.isNotBlank( bannerList )){
            for( Banner banner : bannerList ){
                bannerMap.put( banner.getBannerPosition().toString(),banner);
            }
            return bannerMap;
        }
        return null;
    }

    @Override
    public Banner findBannerByParams(Integer bannerType, Integer bannerPosition) {
        if( UtilTool.isNotBlank( bannerType ) && UtilTool.isNotBlank( bannerPosition )){
            Banner wrapper = new Banner();
            wrapper.setBannerType(bannerType);//所属类别
            wrapper.setBannerPosition(bannerPosition);//所属位置
            Banner banner = bannerMapper.selectOne(wrapper);
            return banner;
        }
        return null;
    }

    @Override
    public List<Banner> findBannerIndexList() {
        Wrapper wrapper = new EntityWrapper<Banner>();
        wrapper.eq("banner_type",Constants.BANNER_TYPE_INDEX);//所属类别
        wrapper.eq("banner_position",Constants.BANNER_POSITION_INDEX);//所属位置
        wrapper.eq("status",YesOrNoEnum.Y.getCode());
        List<Banner> bannerList = bannerMapper.selectList(wrapper);
        if( UtilTool.isNotBlank( bannerList ))
            return bannerList;

        return null;
    }

    @Override
    public List<Banner> findBannerAdvertList() {
        Wrapper wrapper = new EntityWrapper<Banner>();
        wrapper.eq("banner_type",Constants.BANNER_TYPE_ADVERT);//所属类别
        List<Banner> bannerList = bannerMapper.selectList(wrapper);
        if( UtilTool.isNotBlank( bannerList ))
            return bannerList;

        return null;
    }

    @Override
    public List<Banner> findBannerLayoutList() {
        Wrapper wrapper = new EntityWrapper<Banner>();
        wrapper.eq("banner_type",Constants.BANNER_TYPE_LAYOUT);//所属类别
        List<Banner> bannerList = bannerMapper.selectList(wrapper);
        if( UtilTool.isNotBlank( bannerList ))
            return bannerList;

        return null;
    }
}
